<template>
  <ContainerGroup>
    <Container style="height: calc(100vh - 100px)">
      <div style="margin-bottom:20px;">
        <div style="with: 20%; float: left;margin-right:20px;">
          <h3>床位申请</h3>
        </div>
        <div style="with: 80%">
          <div class="btn-box">
            <Button
              style="margin-right: 20px"
              @click="handleAddAplication"
            >申请</Button>
            <Button type="info" @click="handleCancel">取消</Button>
          </div>
        </div>
      </div>

      <div class="list-pannel">
        <div class="list-title">患者信息</div>
        <el-form
          ref="form"
          :model="detail"
          label-width="100px"
          size="small"
          style="margin-top: 15px"
        >
          <el-row>
            <el-col :span="8">
              <el-form-item label="病人姓名：">
                {{ detail.name }}
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="性别：">
                {{ detail.sex == 2 ? "女" : "男" }}
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="身份证：">
                {{ detail.idenno }}
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="拟入院病区：">
                {{ detail.deptName }}
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="入院诊断：">
                {{ detail.diagName }}</el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="list-pannel">
        <div class="list-title">申请床位</div>
        <el-form
          ref="form"
          :model="formInfo"
          label-width="100px"
          size="small"
          style="margin-top: 15px"
        >
          <el-row>
            <el-col :span="8">
              <el-form-item label="是否跨病区：">
                <el-checkbox v-model="formInfo.isCrossNurse" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="床位号：">
                <el-input v-model="formInfo.applicationBedno" />
              </el-form-item>
            </el-col>
          </el-row>
          <!-- <el-row>
            <el-col :span="8">
              <el-form-item label="核酸日期：">
                <el-date-picker
                  style="width: 100%"
                  v-model="formInfo.nucleicacid"
                  type="date"
                  placeholder="选择日期"
                  value-format="yyyy-MM-dd"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row> -->
          <el-row>
            <el-col :span="8">
              <el-form-item label="备注：">
                <el-input
                  v-model="formInfo.remark"
                  type="textarea"
                  :rows="5"
                />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
    </Container>
    <Container>
      <div class="btn-box">
        <!-- <Button style="margin-right: 20px" @click="handleAddAplication"
          >申请</Button
        >
        <Button type="info" @click="handleCancel">取消</Button> -->
      </div>
    </Container>
  </ContainerGroup>
</template>
<script>
import { addAppLiCation, getThisIiPrepayin } from '@/utils/apis/bedApplication'
export default {
  name: '',
  data() {
    return {
      detail: {
        preid: '',
        name: '',
        sex: '',
        diagName: '',
        deptName: ''
      },
      formInfo: {
        isCrossNurse: false, // 0:不是 1:是
        applicationBedno: '',
        remark: ''
        // nucleicacid: "",
      }
    }
  },
  created() {
    console.log('---------', this.getUrlParam('createBy'))
    if (
      this.getUrlParam('preid') === '' ||
      this.getUrlParam('preid') === 'null' ||
      this.getUrlParam('preid') === 'undefined' ||
      this.getUrlParam('createBy') === '' ||
      this.getUrlParam('createBy') === 'null' ||
      this.getUrlParam('createBy') === 'undefined' ||
      this.getUrlParam('jobnumber') === '' ||
      this.getUrlParam('jobnumber') === 'null' ||
      this.getUrlParam('jobnumber') === 'undefined'
    ) {
      this.$message.warning('电子住院证编号/操作人工号/操作人姓名不能为空!')
      return
    }
    this.getInfoData()
  },
  methods: {
    handleCancel() {
      this.formInfo.isCrossNurse = false // 0:不是 1:是
      this.formInfo.applicationBedno = ''
      this.formInfo.remark = ''
      // this.formInfo.nucleicacid = "";
    },
    getUrlParam(name) {
      const query = window.location.search.substring(1)
      const paramArr = query.split('&')
      console.log('paramArr', paramArr)
      for (let i = 0; i < paramArr.length; i++) {
        const pair = paramArr[i].split('=')
        if (pair[0] === name) {
          return pair[1]
        }
      }
      return 'null'
    },
    getInfoData() {
      const param = {
        id: this.getUrlParam('preid')
      }
      getThisIiPrepayin(param).then((res) => {
        if (res.data.code === 200) {
          this.detail = res.data.data
        } else {
          this.$message.error(res.data.message)
        }
      })
    },
    handleAddAplication() {
      if (
        this.getUrlParam('preid') === '' ||
        this.getUrlParam('preid') === 'null' ||
        this.getUrlParam('preid') === 'undefined' ||
        this.getUrlParam('createBy') === '' ||
        this.getUrlParam('createBy') === 'null' ||
        this.getUrlParam('createBy') === 'undefined' ||
        this.getUrlParam('jobnumber') === '' ||
        this.getUrlParam('jobnumber') === 'null' ||
        this.getUrlParam('jobnumber') === 'undefined'
      ) {
        this.$message.warning('电子住院证编号/操作人工号/操作人姓名不能为空!')
        return
      }
      // if (!this.formInfo.nucleicacid) {
      //   this.$message.warning("请选择核酸日期");
      //   return;
      // }
      const param = {
        preid: this.getUrlParam('preid'),
        applicationBedno: this.formInfo.applicationBedno,
        isCrossNurse: this.formInfo.isCrossNurse ? 1 : 0,
        remark: this.formInfo.remark,
        createBy: decodeURI(this.getUrlParam('createBy')),
        jobNumber: this.getUrlParam('jobnumber')
        // nucleicacid: this.formInfo.nucleicacid,
      }
      addAppLiCation(param).then((res) => {
        if (res.data.code === 200) {
          this.$message.success(res.data.message)
        } else {
          this.$message.error(res.data.message)
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
.title {
  border-bottom: 1px solid #dcdfe6;
  padding-bottom: 15px;
  box-sizing: border-box;
  margin-bottom: 20px;
}
.list-title {
  background: #f4f8fb;
  border: 1px solid #e7ecf8;
  color: #555555;
  box-sizing: border-box;
  padding: 10px;
}
.list-pannel {
  margin-bottom: 15px;
}
.btn-box {
  display: inline-flex;
  // justify-content: center;
  // width: 100%;
}
</style>
